Skip to content

chore: bring examples under pyright#43

Merged
chris-colinsky merged 1 commit into
mainfrom
chore/bring-examples-under-pyright
May 15, 2026
Merged

chore: bring examples under pyright#43
chris-colinsky merged 1 commit into
mainfrom
chore/bring-examples-under-pyright

Conversation

@chris-colinsky
Copy link
Copy Markdown
Member

Summary

VS Code's Pylance surfaces type errors on the example files because they're outside pyright's [tool.pyright].include (currently src, tests). Pylance reads the project config, sees the example file isn't in scope, falls back to inferred typing that loses pydantic / openai SDK type info, and emits unknown-member squiggles.

Two changes:

  • pyproject.toml: extend pyright's include to ["src", "tests", "examples"] so the project-wide check covers them and Pylance inherits the same scope.

  • examples/00-hello-world/main.py: with pyright now seeing the example, the trace() observer's event.post_state.sources access becomes a real error. NodeEvent.post_state is typed as the base State, not the subclass PipelineState. Adding an isinstance(event.post_state, PipelineState) check narrows the type for static checkers and acts as a defensive guard against any foreign-state observer event the engine might dispatch (e.g., the LLM-provider span events the comment above already mentions).

All other examples (01-05) come up pyright-clean under project-wide context once they're in scope; no per-file changes needed.

Test plan

  • uv run pyright — 0 errors (was 0 before this PR because examples were out of scope; now 0 with examples in scope).
  • uv run pytest — 503 pass, 84 skipped, 0 failed.
  • VS Code reload + reopen examples/00-hello-world/main.py — the two Pylance "Cannot access attribute 'sources' for class 'State'" errors that surfaced after PR feat(llm): structured output (proposal 0016) #42 merged are gone.

Follow-up

Fast-follow to PR #42 (proposal 0016 structured output). Doc/example surface only — no behavioral changes; runtime path of every example unchanged.

VS Code's Pylance surfaces type errors on the example files because
they're outside pyright's `[tool.pyright].include` (currently src,
tests). Pylance reads the project config, sees the example file isn't
in scope, falls back to inferred typing that loses pydantic / openai
SDK type info, and emits unknown-member squiggles.

Two changes:

- pyproject.toml: extend pyright's include to ["src", "tests",
  "examples"] so the project-wide check covers them and Pylance
  inherits the same scope.

- examples/00-hello-world/main.py: with pyright now seeing the
  example, the trace() observer's `event.post_state.sources` access
  becomes a real error. `NodeEvent.post_state` is typed as the base
  `State`, not the subclass `PipelineState`. Adding an
  `isinstance(event.post_state, PipelineState)` check narrows the
  type for static checkers and acts as a defensive guard against any
  foreign-state observer event the engine might dispatch.

All other examples (01-05) come up pyright-clean under project-wide
context. Confirmed via uv run pyright = 0 errors after the changes.
Copilot AI review requested due to automatic review settings May 15, 2026 22:55
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR brings the examples/ directory under the project’s strict Pyright configuration and updates the hello-world observer example so its state access is statically type-safe.

Changes:

  • Adds examples to [tool.pyright].include.
  • Narrows event.post_state to PipelineState before reading sources in the hello-world trace observer.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
pyproject.toml Expands Pyright coverage to include example files.
examples/00-hello-world/main.py Adds an isinstance guard so observer state access is type-safe.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@chris-colinsky chris-colinsky merged commit 05806b2 into main May 15, 2026
10 checks passed
@chris-colinsky chris-colinsky deleted the chore/bring-examples-under-pyright branch May 15, 2026 22:57
chris-colinsky added a commit that referenced this pull request May 17, 2026
The release workflow's ``Sync deps`` step ran
``uv sync --frozen --all-extras`` without ``--group examples``, so
``openai`` was missing from the venv and the four
``tests/test_examples_smoke.py`` cases failed at module-load time with
``ModuleNotFoundError``. ``ci.yml`` has been doing the right thing
since #43; this brings ``release.yml`` in line.

Surfaced when the v0.6.0 tag fired the workflow for the first time
since #43 landed. The drift sat dormant because release.yml only runs
on tag pushes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants